package com.weixinadmin.http;

import org.apache.log4j.Logger;

import com.weixinadmin.dao.UserSql;
import com.weixindamin.exception.wxexception;

import net.sf.json.JSONObject;

public class wxErrorJson {
	 private static Logger logger = Logger.getLogger(UserSql.class);//log4j
		
	public static int getwxerrorjsonint(String jsonstr) throws wxexception{	
		//{"errcode":40013,"errmsg":"invalid appid"}
		int errcode=-2;
		String errmsg;
		JSONObject json = JSONObject.fromObject(jsonstr);
		try{
			//errmsg = json.getString("errmsg");
			errcode = json.getInt("errcode");
		}catch (Exception e) {
			logger.error("json Exception: "+ jsonstr);
			e.printStackTrace();			
			throw new wxexception(wxexception.jsonerr,jsonstr);				
		} 
		return errcode;
	} 
	public static String getwxerrorjsonstr(String jsonstr) throws wxexception{	
		//{"errcode":40013,"errmsg":"invalid appid"}
		int errcode=-2;
		String errmsg;
		JSONObject json = JSONObject.fromObject(jsonstr);
		try{
			errmsg = json.getString("errmsg");
			//errcode = json.getInt("errcode");
		}catch (Exception e) {
			logger.error("json Exception: "+ jsonstr);
			e.printStackTrace();			
			throw new wxexception(wxexception.jsonerr,jsonstr);				
		} 
		return errmsg;
	}
}
